<?php
    header('Content-Type: text/html;charset=utf-8');
    header("Access-Control-Allow-Origin: *"); // *代表允许任何网址请求
    header('Access-Control-Allow-Methods: *'); // 允许请求的类型
    header('Access-Control-Allow-Credentials: true'); // 设置是否允许发送 cookies
    header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin'); // 设置允许自定义请求头的字段

	$dbms='mysql';     //数据库类型
	$host='localhost'; //数据库主机名
	$dbName='av_porject';    //使用的数据库
	$user='root';      //数据库连接用户名
	$password='root';          //对应的密码
	$dsn="$dbms:host=$host;dbname=$dbName";

    try{
        //1.创建PDO对象
        $pdo = new PDO($dsn,$user,$password);
        //2.设置编码格式
        $pdo->exec("SET names utf8");
        //3.设置错误使用的异常模式
        $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
		// echo ("链接成功");
    }catch (PDOException $e){
        echo $e->getMessage();
        exit;
    }

	$post_str = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
	$postData = json_decode($post_str,true);
	$action = $postData['action'];

	if($action=="search"){
		action_search($pdo,$postData['dbName']);
	}else if($action=='insert'){
        # code...
        action_insert($pdo,$postData['dbName'],$postData['data']);
    }else if($action=='delete'){
        # code...
        action_delete($pdo,$postData['dbName'],$postData['data']);
    }else if ($action=='upData') {
        # code...
        action_upData($pdo,$postData['dbName'],$postData['data']);
    }else if($action=='edit'){
		action_search($pdo,$postData['dbName'],$postData['data']);
	}
